package ch.ethz.fcl.metrobuzz.render.accessbility.interaction;

import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import ch.ethz.fcl.metrobuzz.render.accessbility.AccessibilityRender;

public class AcceTimeScalePanel extends JPanel {
	private static final long serialVersionUID = -7121811087445725047L;

	private JCheckBox timeScaleCB;

	public AcceTimeScalePanel() {
		setBackground(Color.lightGray);
		setBorder(BorderFactory.createTitledBorder("Time Scaled Views"));
		setLayout(new MigLayout());

		timeScaleCB = new JCheckBox("       Time Scaled View",
				AccessibilityRender.TIME_SCALED_VIEW);
		timeScaleCB.setBackground(Color.LIGHT_GRAY);
		timeScaleCB.addItemListener(new CheckBoxChangeListener());

		this.add(timeScaleCB, "wrap");
	}

	public JCheckBox getTimeScaledCB() {
		return timeScaleCB;
	}

	class CheckBoxChangeListener implements ItemListener {
		@Override
		public void itemStateChanged(ItemEvent event) {
			Object source = event.getSource();
			if (source instanceof JCheckBox) {
				JCheckBox cb = (JCheckBox) source;
				if (cb.isSelected()) {
					if (cb.getText().contains("Time Scaled"))
						AccessibilityRender.TIME_SCALED_VIEW = true;

				} else {
					if (cb.getText().contains("Time Scaled"))
						AccessibilityRender.TIME_SCALED_VIEW = false;
				}
			}
		}
	}
}
